<%@page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<%@include file="../global/global.jsp" %>
<%@ page import="com.mfp.java.testYou.core.servlets.ManageUserServlet" %>
<%@ page import="com.mfp.java.testYou.ui.mvc.UserPage" %>
<%UserPage userPage = new UserPage(request, response);%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <jsp:include page="../components/htmlHeader.jsp"></jsp:include>
    <title><testU:i18n>userPage.title</testU:i18n></title>
    <script language="JavaScript" src="<%=cPath%>/testYou/resources/validations.js">
    </script>
</head>
<body class="bgColor textColor">
<jsp:include page="../components/header.jsp"/>
<br><br>
<%if (userPage.hasMessage()) {%>
<center><testU:i18n><%=userPage.getMessage()%>
</testU:i18n></center>
<%}%>
<br>

<form action="<%=cPath%><%=response.encodeURL(ManageUserServlet.URL)%>" method="post" name="userForm"
      onsubmit="return checkFormUser(this)">
    <input type="hidden" name="<%=ManageUserServlet.INPUT_USERID%>" value="<%=userPage.getId()%>">
    <input type="hidden" value="<%=userPage.getOperationName()%>" name="<%=ManageUserServlet.OPERATION%>"/>

    <table class="centerTable30marg padTop3 width40 padLeft17px">
        <tbody>
        <tr>
            <td class="padLeft11">
                <label for="nameId"><testU:i18n>userPage.name</testU:i18n></label>
            </td>
            <td>
                <input id="nameId" type="text" name="<%=ManageUserServlet.INPUT_NAME%>"
                       value="<%=userPage.getUsername()%>"
                   <%if (userPage.isEdit()){%>readonly="readonly"<%}%>/>
            </td>
        </tr>
        <tr>
            <td class="padLeft11">
                <label for="p1Id"><testU:i18n>userPage.pass</testU:i18n></label>
            </td>
            <td>
                <input id="p1Id" type="password" name="<%=ManageUserServlet.INPUT_PASS%>" value="<%=userPage.getPass()%>"/>
            </td>
        </tr>
        <tr>
            <td class="padLeft11">
                <label for="p2Id"><testU:i18n>userPage.confPass</testU:i18n></label>
            </td>
            <td>
                <input id="p2Id" type="password" name="<%=ManageUserServlet.INPUT_CONF_PASS%>" value="<%=userPage.getPass()%>"/>
            </td>
        </tr>
        <tr>
            <td class="padLeft11">
                <label for="role"><testU:i18n>userPage.role</testU:i18n></label>
            </td>
            <td class="padLeft3px">
                <select class="width157px" id="role" name="<%=ManageUserServlet.INPUT_ROLE%>">
                    <c:forEach items="<%=userPage.getRoles()%>" var="role">
                        <option value="${role}"><testU:i18n>main.${role}</testU:i18n></option>
                    </c:forEach>
                </select>
                <script type="text/javascript">
                    document.getElementById('role').selectedIndex = <%=userPage.getUserRoleIndex()%>;
                </script>
            </td>
        </tr>
        <tr>
            <td class="padLeft11">
                <label for="lang"><testU:i18n>userPage.lang</testU:i18n></label>
            </td>
            <td class="padLeft3px">
                <select class="width157px" id="lang" name="<%=ManageUserServlet.INPUT_DEF_LANG%>">
                    <c:forEach items="<%=userPage.getLangs()%>" var="lang">
                        <option value="${lang.id}"><testU:i18n>${lang.key}</testU:i18n></option>
                    </c:forEach>
                </select>
                <script type="text/javascript">
                    document.getElementById('lang').selectedIndex = <%=userPage.getUserLangIndex()%>;
                </script>
            </td>

        </tr>
        <tr>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td class="padLeft17">
                <form><input class="width80px" type="button" value="Back"
                             onClick="window.location.href='<%=cPath%>/testYou/pages/users.jsp'">
                </form>
            </td>
            <td class="padLeft10">
                <%if (userPage.isEdit()) { %>
                <input class="width80px" type="submit" value='<testU:i18n>userPage.edit</testU:i18n>'>
                <%} else { %>
                <input class="width80px" type="submit" value='<testU:i18n>userPage.new</testU:i18n>'>
                <%}%>

            </td>
        </tr>
        </tbody>
    </table>
</form>
</body>
</html>